#!/usr/bin/perl -w

use strict;
use warnings;
use Data::Dumper;

our $path = 'Value';

open (FB , "css2_properties_index.html");
      my @d = <FB>;
close FB;

my $t = join "" , @d;
my @res = ();

while ($t =~ /<a href="([^"]+)" class="noxref"><span class="([^"]+)">'([^']+)'/g) {
      push @res , $3;
}


my %seen = ();
my @list = grep { ! $seen{$_} ++ } @res;

@list = sort { $a cmp $b } @list;
push @list , "";

my @new = ();

foreach (@list) {
      
      my @t = split /-/ , $_;
      
      foreach (@t) {
            $_ = ucfirst($_);
      }
      
      push @new , join "" , @t;
      
}

print Dumper \@new;
die;

&generate(\@new);

sub generate {
      my ($list) = @_;
      
      #print Dumper $list;
      #return;
      
      foreach my $item (@$list) {
            
            my $module_name = $item;
            
            
            print "Generating module: " , ucfirst($module_name) , ".pm\n";
            if (-e $path . "/" . $module_name . ".pm") {
                  print "\t\tAlready exists\n";
            } else {
                  
                  open (FH , ">>$path/". ucfirst($module_name) . ".pm");
                        print FH "package CSS::Builder::Value::". ucfirst($module_name) . ";\n";
                        print FH "use Moose;\n\n";
                        
                        print FH "extends 'CSS::Builder::Value';\n\n";
                        
                        print FH "has \'value\' => ( isa => 'Any' , is => 'rw' );";
                        
                        
                        print FH "\n\n1;";
                        
                        
                  close FH;
            }
            
      }
      #print Dumper $list;
}




